var host = process.env.HOST;

export default function(obj) {
	return new Promise((resolve, reject) => {
		let user_token=uni.getStorageSync('USER_TOKEN');
		let user_id=uni.getStorageSync('USER_ID');
		if(obj.data.token) user_token=obj.data.token;
		uni.request({
			url:  host+obj.url,
			data: Object.assign(obj.data),
			method: obj.method,
			header: {
				'user-token': user_token ,//自定义请求头信息
				'user-id': user_id //自定义请求头信息
			},
			success: (res) => {
				let opt=obj.data["opt"];
				let data = res.data
				
				if(opt&&opt["data_type"]=="string"){
					if(data){
						resolve(data);
					}else{
						resolve();
					}
				}else{
					if (data.code == 200) {
						resolve(data.data)
					} else {
						uni.showToast({icon:"none",title: data.msg});
						resolve();
					}
				}
				

			},
			fail: (error) => {
				reject(/*Message.error('服务器异常')*/)
			}
		});
		
	})
}
